package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/8/12 09:50
 * @apiNote
 */

public class Test00762CountPrimeSetBits {
    public int countPrimeSetBits(int left, int right) {
        int ans = 0;
        for(int x = left; x <= right; x++){
            if(isPrime(Integer.bitCount(x))){
                ans++;
            }
        }
        return ans;
    }

    private boolean isPrime(int x){
        if(x < 2){
            return false;
        }
        for(int i = 2;i*i <= x ; i++){
            if(x % i == 0){
                return false;
            }
        }
        return true;
    }
}
